home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / mgr / sparcmgr / src.zoo / src / print.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-03-17  |  4.2 KB  |  240 lines

  1. /*                        Copyright (c) 1987 Bellcore
  2.  *                            All Rights Reserved
  3.  *       Permission is granted to copy or use this program, EXCEPT that it
  4.  *       may not be sold for profit, the copyright notice must be reproduced
  5.  *       on copies, and credit should be given to Bellcore where it is due.
  6.  *       BELLCORE MAKES NO WARRANTY AND ACCEPTS NO LIABILITY FOR THIS PROGRAM.
  7.  */
  8. /*    $Header: print.c,v 1.1 89/03/17 08:21:18 sau Exp $
  9.     $Source: /m1/mgr.new/src/RCS/print.c,v $
  10. */
  11. static char    RCSid_[] = "$Source: /m1/mgr.new/src/RCS/print.c,v $$Revision: 1.1 $";
  12.  
  13. /* debugging routines for printing status info */
  14.  
  15. #include <stdio.h>
  16.  
  17. static char *flags[] = { 
  18.    "active",
  19.    "escape",
  20.    "snarfable",
  21.    "reverse",
  22.    "standout",
  23.    "died",
  24.    "expose",
  25.    "background",
  26.    "nokill",
  27.    "vi",
  28.    "downloading",
  29.    "noinput",
  30.    "nowrap",
  31.    "overstrike",
  32.    "abs-coords",
  33.    "minus",
  34.    "snarf-lines",
  35.    "snarf-tabs",
  36.    "snarf-hard",
  37.    (char *) 0
  38.    };
  39.  
  40. static char *events[] = {
  41.    "1_up",
  42.    "no-event",
  43.    "2_up",
  44.    "3_up",
  45.    "no-event",
  46.    "3_down",
  47.    "2_down",
  48.    "no-event",
  49.    "1_down",
  50.    "shape",
  51.    "redraw",
  52.    "activated",
  53.    "deactivated",
  54.    "covered",
  55.    "uncovered",
  56.    "moved",
  57.    "destroyed",
  58.    "accept",
  59.    "notify",
  60.    "tell-me",
  61.    "snarfed",
  62.    "paste",
  63.    "stack",
  64.    "stack_flag",
  65.    (char *) 0
  66.    };
  67.  
  68. static char *stack[] = {
  69.    "menu",
  70.    "event",
  71.    "font",
  72.    "cursor",
  73.    "bitmap",
  74.    "position",
  75.    "window",
  76.    "flags",
  77.    "mouse",
  78.    "text",
  79.    "CLEAR",
  80.    (char *) 0
  81.    };
  82.  
  83. static char *menu_states[] = {
  84.     "choice",
  85.     "bottom",
  86.     "top",
  87.     "top & bottom",
  88.     "left",
  89.     "left & bottom",
  90.     "left & top",
  91.     "left & top & bottom",
  92.     "right",
  93.     "right & bottom",
  94.     "right & top",
  95.     "right & top & bottom",
  96.     "right & left",
  97.     "right & left & bottom",
  98.     "right & left & top",
  99.     "right & left & top & bottom",
  100.    };
  101.  
  102. static char buff[512];
  103.  
  104. /* get flag names */
  105.  
  106. char *print_flags(n)
  107. int n;
  108.    {
  109.    char *binary();
  110.    register int i,j;
  111.  
  112.    sprintf(buff,"(%s)",binary(n));
  113.    for(j=1,i=0;flags[i];i++,j<<=1)
  114.       if (j&n) {
  115.          if (*buff) strcat(buff,",");
  116.          strcat(buff,flags[i]);
  117.          }
  118.    return(buff);
  119.    }
  120.  
  121. /* get menu states */
  122.  
  123. char
  124. *print_menu(n)
  125. int n;        /* menu state */
  126.    {
  127.    return(menu_states[n%16]);
  128.    }
  129.  
  130. /* get stack codes */
  131.  
  132. char *print_stack(n)
  133. int n;
  134.    {
  135.    register int i,j;
  136.    char *binary();
  137.  
  138.    sprintf(buff,"(%s)",binary(n));
  139.    for(j=1,i=0;stack[i];i++,j<<=1)
  140.       if (j&n) {
  141.          if (*buff) strcat(buff,",");
  142.          strcat(buff,stack[i]);
  143.          }
  144.    return(buff);
  145.    }
  146.  
  147. /* get event names */
  148.  
  149. char *print_events(n)
  150. int n;
  151.    {
  152.    register int i,j;
  153.    char *binary();
  154.  
  155.    sprintf(buff,"(%s)",binary(n));
  156.    for(j=1,i=0;events[i];i++,j<<=1)
  157.       if (j&n) {
  158.          if (*buff) strcat(buff,",");
  159.          strcat(buff,events[i]);
  160.          }
  161.    return(buff);
  162.    }
  163.  
  164.  
  165. /* get ps info */
  166.  
  167. static char *list[100];
  168. static int p_count = 0;
  169.  
  170. int
  171. get_ps()
  172.    {
  173.    FILE *popen(), *ps = popen("ps a","r");
  174.    char line[81];
  175.    char *index(), *save_line();
  176.  
  177.    fgets(line,sizeof(line),ps);
  178.    while(fgets(line,sizeof(line),ps) != NULL) {
  179.       list[p_count++] = save_line(line+6);
  180.       }
  181.    pclose(ps);
  182.    return(p_count);
  183.    }
  184.  
  185. int
  186. free_ps()
  187.    {
  188.    register int i;
  189.  
  190.    for(i=0;i<p_count;i++) {
  191.       if (list[i])
  192.          free(list[i]);
  193.       }
  194.    p_count = 0;
  195.    }
  196.  
  197. char *
  198. print_ps(tty)
  199. char *tty;
  200.    {
  201.    register int i;
  202.    register char *check = tty + (strlen(tty) - 2);
  203.    register char *p1,*p2;
  204.    char *index(), *strcpy();
  205.  
  206.    *buff = '\0';
  207.    for(i=0;i<p_count;i++)
  208.       if (list[i] && strncmp(check,list[i],2)==0 &&
  209.                      (int)(p1 = index(list[i],':')+4)>4) {
  210.          if (p2 = index(p1,'\n'))
  211.             *p2 = '\0';
  212.          strcpy(buff,p1);
  213.          if (*p1 != '-')
  214.             break;
  215.          }
  216.    return(buff ? buff : strcpy(buff,"?? unknown ??"));
  217.    } 
  218.  
  219. /*****************************************************************************
  220.  *    print x in binary
  221.  */
  222.  
  223. char *
  224. binary(x)
  225. int x;
  226.    {
  227.    register int i;
  228.    static char out[33];
  229.    int n=32;
  230.  
  231.    out[n+1] = '\0';
  232.    for(i=0;i<n+1;i++)
  233.       if (x&(1<<i))
  234.          out[n-i] = '1';
  235.       else
  236.          out[n-i] = '0';
  237.    for(i=0;out[i]=='0' && i<33;i++);
  238.    return(i>0?out+i-1:out);
  239.    }
  240.